package com.linyaonan.leetcode.easy._1185;

import java.util.Calendar;

/**
 * 给你一个日期，请你设计一个算法来判断它是对应一周中的哪一天。
 * <p>
 * 输入为三个整数：day、month 和 year，分别表示日、月、年。
 * <p>
 * 您返回的结果必须是这几个值中的一个 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}。
 * <p>
 *  
 * <p>
 * 示例 1：
 * <p>
 * 输入：day = 31, month = 8, year = 2019
 * 输出："Saturday"
 * 示例 2：
 * <p>
 * 输入：day = 18, month = 7, year = 1999
 * 输出："Sunday"
 * 示例 3：
 * <p>
 * 输入：day = 15, month = 8, year = 1993
 * 输出："Sunday"
 *
 * @author: Lin
 * @date: 2020/1/8
 */
public class DayOfTheWeek {

    public String dayOfTheWeek(int day, int month, int year) {
        Calendar instance = Calendar.getInstance();
        // 需要注意月份是从0开始到11，所以需要先自减
        instance.set(year, --month, day);
        int weekday = instance.get(Calendar.DAY_OF_WEEK);
        String week;
        switch (weekday) {
            case 1:
                week = "Sunday";
                break;
            case 2:
                week = "Monday";
                break;
            case 3:
                week = "Tuesday";
                break;
            case 4:
                week = "Wednesday";
                break;
            case 5:
                week = "Thursday";
                break;
            case 6:
                week = "Friday";
                break;
            case 7:
                week = "Saturday";
                break;
            default:
                week = "Saturday";
        }
        return week;
    }
}
